/*
 * @Description:
 * @Author: Cxy
 * @Date: 2023-07-10 11:15:19
 * @LastEditors: Cxy
 * @LastEditTime: 2024-05-06 12:27:16
 * @FilePath: \blogAdmin\play\src\i18n\index.ts
 */
import { type I18n, createI18n } from 'vue-i18n'
import { configStore } from '@/stores/config'

const langFileData = import.meta.glob('./lang/**/*.json(5)?', { eager: true })
const messages: any = Object.values(langFileData).reduce((prev: any, c: any) => {
  Object.keys(c.default).forEach((cc: any) => {
    prev[cc] = { ...c.default[cc], ...prev[cc] }
  })
  // const lang = key.match(/([\u2E80-\u9FFF]|[a-z-_])+(?=\.)/gi)[0]
  return prev
}, {})

export const langType = Object.keys(messages)

export const langData = Object.keys(messages[langType[0]])

export const i18n: I18n = createI18n({
  locale: configStore.config.locale, // 设置地区
  messages, // 设置地区信息
  legacy: false,
  globalInjection: false //全局不生效$t
})
